/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.core.multithreading;

/**
 *
 * @author sunil
 */
public class MultiThread1 {

    public static void main(String[] args) throws InterruptedException {

        String name = "sunil";
        String su = "sunilsss";
        Thread tFirst = new Thread(new RunnableThread("FIRST", name));
        //Thread tSecond = new Thread(new RunnableThread("SECOND", name));

        tFirst.start();
        //tSecond.start();
        //tFirst.sleep(10000);


        synchronized (name) {
            System.out.println("===========================> LOCK");
            name.wait();
        }

        System.out.println("===========================> Started Now");



    }
}

class RunnableThread implements Runnable {

    String name;

    public RunnableThread(String tName, String myName) {
        this.name = myName;
    }

    public void run() {

        for (int i = 0; i < 10; i++) {
            try {
                System.out.println("============================> " + name + "_" + i);
                Thread.currentThread().sleep(1000);
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
        }

        synchronized (name) {
            System.out.println("================>  UNLOCKED ");
            name.notify();

        }
        ;

    }
}
